//
//  Collection.m
//  Tupianliulanqi
//
//  Created by zzn on 2016/12/27.
//  Copyright © 2016年 zzn. All rights reserved.
//

#import "Collection.h"
#import "CollectionViewCell.h"
#import "ScollViewController.h"
#import "Collection2ViewController.h"
#import "View2Controller.h"
#import "View3Controller.h"

@interface Collection ()<UIImagePickerControllerDelegate,UINavigationControllerDelegate>
{
    int time;
    NSMutableArray <UIImage *>*photo;
}

@end

@implementation Collection

static NSString * const reuseIdentifier = @"Cell";

- (void)viewDidLoad {
    [super viewDidLoad];
    photo = [NSMutableArray new];
    self.collectionView.backgroundColor = [UIColor whiteColor];
    UICollectionViewFlowLayout *flow = (UICollectionViewFlowLayout *)self.collectionView.collectionViewLayout;
    flow.minimumLineSpacing = 4;
    flow.minimumInteritemSpacing = 4;
    
    time = 1;
}

- (IBAction)onPhoto:(id)sender {
    UIImagePickerController *pick = [UIImagePickerController new];
    pick.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    pick.delegate = self;
    [self presentViewController:pick animated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
    NSLog(@"%@",info);
    [photo addObject:info[@"UIImagePickerControllerOriginalImage"]];
    [self.collectionView reloadData];
    
}


- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return photo.count;
}

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    UICollectionReusableView *reusa = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"re" forIndexPath:indexPath];
    return reusa;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"id" forIndexPath:indexPath];
 //   cell.imagView.image = photo[indexPath.item];
 //   cell.imlabel.text = [NSString stringWithFormat:@"2016.12.%d",time++];
    cell.backgroundColor = [UIColor greenColor];
    
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    //    ScollViewController *con = [self.storyboard instantiateViewControllerWithIdentifier:@"scoll"];
    //    con.image = photo;
    //    [self presentViewController:con animated:YES completion:nil];
    
    //    Collection2ViewController *coll2 = [self.storyboard instantiateViewControllerWithIdentifier:@"collec2"];
    //    coll2.img = photo;
    //    [self presentViewController:coll2 animated:YES completion:nil];
    
    //    View2Controller *view2 = [[View2Controller alloc]init];
    //    view2.image = photo[indexPath.item];
    //
    //    view2.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    //    [self presentViewController:view2 animated:YES completion:nil];
    
    UIViewController *view3 = [[UIViewController alloc]init];
 //   view3.im = photo;
 //   view3.cur = indexPath.item;
    [self presentViewController:view3 animated:YES completion:nil];
    
}

- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds
{
    return YES;
}

#pragma mark <UICollectionViewDelegate>

/*
 // Uncomment this method to specify if the specified item should be highlighted during tracking
 - (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath {
	return YES;
 }
 */

/*
 // Uncomment this method to specify if the specified item should be selected
 - (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {
 return YES;
 }
 */

/*
 // Uncomment these methods to specify if an action menu should be displayed for the specified item, and react to actions performed on the item
 - (BOOL)collectionView:(UICollectionView *)collectionView shouldShowMenuForItemAtIndexPath:(NSIndexPath *)indexPath {
	return NO;
 }
 
 - (BOOL)collectionView:(UICollectionView *)collectionView canPerformAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
	return NO;
 }
 
 - (void)collectionView:(UICollectionView *)collectionView performAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
	
 }
 */

@end
